#version 120

varying vec2 VertTexcoord;

uniform sampler2D TexUnit0;
uniform vec4 TexScaleOffset = vec4(1.0, 1.0, 0.0, 0.0);
uniform vec4 uModulateColor = vec4(1.0, 1.0, 1.0, 1.0);
uniform vec4 uAdditiveColor = vec4(0.0, 0.0, 0.0, 0.0);
uniform vec2 uTiles = vec2(1.0,1.0);
uniform float Alpha = 1.0;

void main()
{
	vec2 scale = TexScaleOffset.xy;
	vec2 offset = TexScaleOffset.zw;
	vec2 ResultTexCoord;
	if((uTiles.x != 1.0) || (uTiles.y != 1.0))	
		ResultTexCoord = fract(VertTexcoord * uTiles) * scale + offset;	
	else
		ResultTexCoord = VertTexcoord * scale + offset;
	vec4 FinalColor = texture2D(TexUnit0, ResultTexCoord);
	gl_FragColor = FinalColor * uModulateColor + uAdditiveColor;
	gl_FragColor.a = Alpha * (FinalColor.a + uAdditiveColor.a);
}
